package edu.njust.service;

import edu.njust.dao.UserMapper;
import edu.njust.pojo.Message;
import edu.njust.utils.DateUtils;

import java.text.ParseException;
import java.util.Date;
import java.util.List;

public class MessageServiceImpl implements MessageService{

    private UserMapper userMapper;

    public UserMapper getUserMapper() {
        return userMapper;
    }

    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    DateUtils dateUtils = new DateUtils();

    @Override
    public void sendMessage(String send_user, List<String> receive_userList, String context){
        Date date = new Date();
        for (String receive_user : receive_userList){
            Long id = userMapper.getLastMessageId();
            id += 1;
            Message message = new Message(id, send_user, receive_user, date, context);
            userMapper.addMessage(message);
        }
    }

    @Override
    public List<Message> showAllMessage(String receiver_id) {
        return userMapper.showAllMessage(receiver_id);
    }
}
